home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr26 / netprog.zip / NETPROG.TAR / net / strcli.c < prev    next >
C/C++ Source or Header  |  1989-12-17  |  896b  |  39 lines

  1. /*
  2.  * Read the contents of the FILE *fp, write each line to the
  3.  * stream socket (to the server process), then read a line back from
  4.  * the socket and write it to the standard output.
  5.  *
  6.  * Return to caller when an EOF is encountered on the input file.
  7.  */
  8.  
  9. #include    <stdio.h>
  10. #define    MAXLINE    512
  11.  
  12. str_cli(fp, sockfd)
  13. register FILE    *fp;
  14. register int    sockfd;
  15. {
  16.     int    n;
  17.     char    sendline[MAXLINE], recvline[MAXLINE + 1];
  18.  
  19.     while (fgets(sendline, MAXLINE, fp) != NULL) {
  20.         n = strlen(sendline);
  21.         if (writen(sockfd, sendline, n) != n)
  22.             err_sys("str_cli: writen error on socket");
  23.  
  24.         /*
  25.          * Now read a line from the socket and write it to
  26.          * our standard output.
  27.          */
  28.  
  29.         n = readline(sockfd, recvline, MAXLINE);
  30.         if (n < 0)
  31.             err_dump("str_cli: readline error");
  32.         recvline[n] = 0;    /* null terminate */
  33.         fputs(recvline, stdout);
  34.     }
  35.  
  36.     if (ferror(fp))
  37.         err_sys("str_cli: error reading file");
  38. }
  39.